/**
 Copyright (c) 2021-present, Eaton

 All rights reserved.

 This code is licensed under the BSD-3 license found in the LICENSE file in the root directory of this source tree and at https://opensource.org/licenses/BSD-3-Clause.
 **/
import 'react-app-polyfill/stable';
import ReactDOMClient from 'react-dom/client';
import { unstable_HistoryRouter as HistoryRouter } from 'react-router-dom';
import { customHistory } from './router/main'
import { StyledEngineProvider } from '@mui/material/styles';
import '@brightlayer-ui/react-themes/open-sans';
import './index.scss';
import App from './App';
import reportWebVitals from './reportWebVitals';
import { PersistGate } from "redux-persist/integration/react";
import { Provider } from "react-redux";
import { store, persistor } from "./redux";
import AuthRouter from "./router/utils/authRouter";
import { HTML5Backend } from 'react-dnd-html5-backend'
import { DndProvider } from 'react-dnd'
import { APILoader } from '@uiw/react-amap-api-loader';
import './assets/iconfont/iconfont.css'

const container = document.getElementById('root');
if (!container) throw new Error('Root Element was not found in the DOM');

const root = ReactDOMClient.createRoot(container);
// console.log(store.getState().auth.theme, 'store.getState().auth.theme')
root.render(
  <StyledEngineProvider injectFirst>
    <HistoryRouter history={customHistory}>
      <Provider store={store}>
        <PersistGate persistor={persistor}>
          <APILoader akay="c9f8993c425b3c7ca31d66f307e4145d" plugin="AMap.Weather,AMap.RangingTool,AMap.Scale,AMap.ToolBar">
            <DndProvider backend={HTML5Backend}>
              <AuthRouter>
                <App />
              </AuthRouter>
            </DndProvider>
          </APILoader>
        </PersistGate>
      </Provider>
    </HistoryRouter>
  </StyledEngineProvider>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
